<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="resource/save" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" value='${obj.title!""}' required="required" lay-verify="required" title="请输入标题" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">子标题</label>
        <div class="layui-input-block">
            <input type="text" name="subtitle" value='${obj.subtitle!""}' placeholder="请输入子标题" class="layui-input">
        </div>
        <label class="layui-input-inline layui-word-aux">(营销文案)</label>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">地区</label>
        <div class="layui-input-inline">
        	<select name="region" required="required" lay-verify="required">
       		    <option value="" >请选择</option>
       		    <#list region_list as _region>
			    <option value="${_region.id}" ${((_region.id)==(obj.region!0))?string("selected","")} >${_region.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">语言</label>
        <div class="layui-input-inline">
        	<select name="language" required="required" lay-verify="required">
        		<option value="" >请选择</option>
		        <#list language_list as _language>
			    <option value="${_language.id}" ${((_language.id)==(obj.language!0))?string("selected","")} >${_language.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">来源</label>
        <div class="layui-input-inline">
        	<select name="source" required="required"  lay-verify="required">
        		<option value="" >请选择</option>
		        <#list source_list as _source>
			    <option value="${_source.id}" ${((_source.id)==(obj.source!0))?string("selected","")} >${_source.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">年份</label>
        <div class="layui-input-inline">
            <input type="text" name="year" value='${obj.year?c}' required="required" lay-verify="number" title="请输入年份" placeholder="请输入年份" class="layui-input">
        </div>
        <label class="layui-input-inline layui-word-aux">(例如：2017)</label>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">频道</label>
        <div class="layui-input-inline">
        	<select name="channel" required="required" lay-verify="required">
        		<option value="" >请选择</option>
		        <#list channel_list as _channel>
			    <option value="${_channel.id}" ${((_channel.id)==(obj.channel!0))?string("selected","")} >${_channel.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-inline">
        	<select name="type" required="required" lay-verify="required">
        		<option value="" >请选择</option>
		        <#list type_list as _type>
			    <option value="${_type.id}" ${((_type.id)==(obj.type!0))?string("selected","")} >${_type.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">年龄段</label>
        <div class="layui-input-inline">
        	<select name="age" required="required" lay-verify="required">
        		<option value="" >请选择</option>
		        <#list age_list as _age>
			    <option value="${_age.id}" ${((_age.id)==(obj.age!0))?string("selected","")} >${_age.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-inline" style="width: 50%;">
	    <label class="layui-form-label">是否精选</label>
	    <div class="layui-input-block">
	      <input type="checkbox" name="selected" ${(obj.selected)?string("checked","")} value='1' lay-skin="switch" lay-text="是|否">
	    </div>
	</div>
    <div class="layui-inline">
        <label class="layui-form-label">课堂分类</label>
        <div class="layui-input-inline">
        	<select name="school">
        		<option value="0" >请选择</option>
		        <#list school_list as _school>
			    <option value="${_school.id}" ${((_school.id)==(obj.school!0))?string("selected","")} >${_school.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    
    <div class="layui-inline">
        <label class="layui-form-label">心智养成</label>
        <div class="layui-input-inline">
        	<select name="program">
        		<option value="0" >请选择</option>
		        <#list program_list as _program>
			    <option value="${_program.id}" ${((_program.id)==(obj.program!0))?string("selected","")} >${_program.name}</option>
			    </#list>
		    </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">IP名称</label>
        <div class="layui-input-block">
            <input type="text" name="ipname" value='${obj.ipname!""}' required="required" lay-verify="required" placeholder="请输入IP名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">简介</label>
	    <div class="layui-input-block">
	      <textarea name="describe" placeholder="请输入内容" class="layui-textarea">${obj.describe!""}</textarea>
	    </div>
	 </div>
	 <div class="layui-form-item">
        <label class="layui-form-label">IP图片</label>
        <div class="layui-input-inline">
        	<img data-tips-image="" style="height:auto;max-height:60px;min-width:60px" src="${obj.ipimg!''}" id="img_src2"/>
            <input type="hidden" id="ipimg" name="ipimg" value="${obj.ipimg!''}" required="required" lay-verify="required" class="layui-input">
            <input type="file" name="file" class="layui-upload-file" id="img_file2" >
        </div>
        <label class="layui-input-inline layui-word-aux">(尺寸：260x380)</label>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">影片海报</label>
        <div class="layui-input-inline">
        	<img data-tips-image="" style="height:auto;max-height:60px;min-width:60px" src="${obj.img!''}" id="img_src"/>
            <input type="hidden" id="img" name="img" value="${obj.img!''}" required="required" lay-verify="required" class="layui-input">
            <input type="file" name="file" class="layui-upload-file" id="img_file" >
        </div>
        <label class="layui-input-inline layui-word-aux">(尺寸：260x380)</label>
    </div>
    
    <div class="hr-line-dashed"></div>
    <div class="layui-form-item text-center">
        <input type='hidden' value='${obj.id?c}' name='id'/>
        <input type='hidden' value='${obj.status?c}' name='status'/>
        <button class="layui-btn" type='button' lay-submit lay-filter="*">保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>

    <script>window.form.render();</script>
</form>
<div class="loading_img"></div>
<script>
layui.use(['form','upload'], function(){
	var form = layui.form();
	
	//监听提交
    form.on('submit(*)', function (data) {
    	console.log(data.field);
    	$.post('resource/save', data.field, function (result) { 
			if(result.code==1){
	        	layer.closeAll();
	            layer.msg(result.msg, {
	                icon: 1,
	                shade: this.shade,
	                scrollbar: false,
	                time: 2000,
	                shadeClose: true
	            });//保存成功提示
	            $.form.reload();//刷新表单
	        }else{
	            layer.msg(result.msg, {
	                icon: 2,
	                shade: this.shade,
	                scrollbar: false,
	                time: 3000,
	                shadeClose: true
	            });
	        }
	        
		},"json");
        return false;
    });
	
    layui.upload({
	  elem: '#img_file',
	  url: 'file/upload',
	  ext: 'jpg|png|gif',
	  before:function(res){
		  $(".loading_img").show();
	  },
	  success: function(res){
	    if(res.code==0){
	    	var img_str = res.data.path;
	    	$("#img_src").attr("src",img_str);
	    	$("#img").val(img_str);
	    }else{
	    	layer.msg("上传失败", {
                icon: 2,
                shade: this.shade,
                scrollbar: false,
                time: 3000,
                shadeClose: true
            });
	    }
	    $(".loading_img").hide();
	  }
	});
    
    layui.upload({
  	  elem: '#img_file2',
  	  url: 'file/upload',
  	  ext: 'jpg|png|gif',
  	  before:function(res){
  		  $(".loading_img").show();
  	  },
  	  success: function(res){
  	    if(res.code==0){
  	    	var img_str = res.data.path;
  	    	$("#img_src2").attr("src",img_str);
  	    	$("#ipimg").val(img_str);
  	    }else{
  	    	layer.msg("上传失败", {
                  icon: 2,
                  shade: this.shade,
                  scrollbar: false,
                  time: 3000,
                  shadeClose: true
              });
  	    }
  	    $(".loading_img").hide();
  	  }
  	});
	  
});
</script>